﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.DAL;
using MINERP.DAL.PrintManage;
using MINERP.MODEL.FoundationModel;
using MINERP.MODEL.PrintManage;

namespace MINERP.BLL.PrintManage
{
    public  class PrinterBLL
    {
        #region //Private Fields


        #endregion


        #region //Public Properties

        #endregion



        #region //Public Methods

        public Printer_Info GetPrinterObj(int id)
        {
            Printer_Info printerInfo = new Printer_Info();
            using (newSampleYPDBEntities enty = new newSampleYPDBEntities())
            {
                printer printerobj = enty.printer.FirstOrDefault(p => p.PrinterID == id);
                printerInfo.HotDirPath = printerobj.hotDirPath;
                printerInfo.ICCPath = printerobj.ICCPath;
                printerInfo.IsTransverse = (bool)printerobj.IsTransverse;
                printerInfo.MonitorDirPath = printerobj.MonitorDirPath;
                printerInfo.PDes = printerobj.PDes;
                printerInfo.PDPI = printerobj.PDPI;
                printerInfo.PLength = printerobj.PLength;
                printerInfo.PName = printerobj.PName;
                printerInfo.PrinterID = printerobj.PrinterID;
                printerInfo.PType = printerobj.PType;
                printerInfo.PWidth = printerobj.PWidth;
                printerInfo.Status = printerobj.status;
                printerInfo.Status2 = (int)printerobj.status2;
                //printerInfo.GridNum = printerobj.GridNum == null ? 0 : (int)printerobj.GridNum;
            }
            return printerInfo;
        }

        public Printer_Info GetPrinterObj(string  name)
        {
            Printer_Info printerInfo = new Printer_Info();
            using (newSampleYPDBEntities enty = new newSampleYPDBEntities())
            {
                printer printerobj = enty.printer.FirstOrDefault(p => p.PName == name);
                printerInfo.HotDirPath = printerobj.hotDirPath;
                printerInfo.ICCPath = printerobj.ICCPath;
                printerInfo.IsTransverse = (bool)printerobj.IsTransverse;
                printerInfo.MonitorDirPath = printerobj.MonitorDirPath;
                printerInfo.PDes = printerobj.PDes;
                printerInfo.PDPI = printerobj.PDPI;
                printerInfo.PLength = printerobj.PLength;
                printerInfo.PName = printerobj.PName;
                printerInfo.PrinterID = printerobj.PrinterID;
                printerInfo.PType = printerobj.PType;
                printerInfo.PWidth = printerobj.PWidth;
                printerInfo.Status = printerobj.status;
                printerInfo.Status2 = (int)printerobj.status2;
                //printerInfo.GridNum = printerobj.GridNum == null ? 0 : (int)printerobj.GridNum;
            }
            return printerInfo;
        }

        public List<Printer_Info> GetPrinterInfoList()
        {
            List<Printer_Info> list = new List<Printer_Info>();
            using (newSampleYPDBEntities enty = new newSampleYPDBEntities())
            {
                List<printer> printerList = enty.printer.ToList();
                foreach (var printerobj in printerList)
                {
                    Printer_Info printerInfo = new Printer_Info();
                    printerInfo.ICCPath = printerobj.ICCPath;
                    printerInfo.IsTransverse = (bool)printerobj.IsTransverse;
                    printerInfo.MonitorDirPath = printerobj.MonitorDirPath;
                    printerInfo.PDes = printerobj.PDes;
                    printerInfo.PDPI = printerobj.PDPI;
                    printerInfo.PLength = printerobj.PLength;
                    printerInfo.PName = printerobj.PName;
                    printerInfo.PrinterID = printerobj.PrinterID;
                    printerInfo.PType = printerobj.PType;
                    printerInfo.PWidth = printerobj.PWidth;
                    printerInfo.Status = printerobj.status;
                    printerInfo.Status2 = (int)printerobj.status2;
                    //printerInfo.GridNum = printerobj.GridNum == null ? 0 : (int)printerobj.GridNum;
                    list.Add(printerInfo);
                    
                }
                
            }
            return list;
        }

      
        #endregion
    }
}
